<?php
/**
 * Description of mysql
 *
 * @author voellenk
 */
class mysql {
  public $dbhost;
  public $dbname;
  public $dbuser;
  public $dbpassword;
  public $error;
  private $connection;

  public function __construct($host, $user, $pass) {
    $this->dbhost = $host;
    $this->dbuser = $user;
    $this->dbpassword = $pass;
  }
  
  public function connect($name="") {
    if (!empty($name)) {
      $this->dbname = $name;
    }
    $this->connection = mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
    if (!$this->connection) {
      echo ("could not connect to database.".mysql_error()."\n");
      return false;
    }
    if (!mysql_select_db($this->dbname, $this->connection)) {
      echo ("could not select database $name".mysql_error()."\n");
      return false;
    }
    return true;
  }
  
  public function select($sql) {
    $result = mysql_query($sql);
    if ($result) {
      $arr= mysql_fetch_array($result);
      mysql_free_result($result);
      return ($arr);
    }
    $this->error = "select error: ".mysql_error();
  }
  
  public function insert($sql) {
    $result = mysql_query($sql);
    $this->error = "insert error: ".mysql_error();
    return ($result);
  }
  
  public function disconnect() {
    if (is_resource($this->connection)) {
      mysql_close($this->connection);
    }
  }
}

?>
